package com.h;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	
	private Context context;
	
	private List<Object> list=new ArrayList<Object>();
	
	public MyAdapter(Context context) {
		this.context=context;
	}
	
	
	
	private Object[] pool=new Object[list.size()];
	

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		System.out.println("-------------- P:"+position);
//		if(convertView!=null){
//			return convertView;
//		}
		
		
		if(pool[position]!=null){
			return (View) pool[position];
		}
		
		
		TextView tv=new TextView(context);
		System.out.println("-------------- Px:"+position);
		
		tv.setText("p:"+position);
		pool[position]= tv;
		return tv;
	}

	public void add(List<Object> d){
		list.addAll(d);
		pool=ArrayUtil.addLength(pool, d.size());
	}
}
